package com.erp.web.erp.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.erp.base.business.entity.AppUser;
import com.erp.base.common.utils.OperationResult;
import com.erp.web.erp.service.ErpIndexService;

/**
 * @author whw
 */
@RequestMapping("/erp/index")
@Controller
public class ErpIndexController {
	@Autowired
	private ErpIndexService erpIndexService;
	
	/**
	 * 获取城市接口
	 * @return
	 */
	@RequestMapping("/city")
	@ResponseBody
	public OperationResult getCity(){
		return erpIndexService.getCity();
	}
	/**
	 * 根据省份id获取城市
	 * @param provincialId 省份id
	 * @return
	 */
	@RequestMapping("/cityByProvincial")
	@ResponseBody
	public OperationResult getCityByProvincial(long provincialId){
		return erpIndexService.getCityByProvincial(provincialId);
	}
	/**
	 * 获取省份id
	 * @return
	 */
	@RequestMapping("/provincial")
	@ResponseBody
	public OperationResult getProvincial(){
		return erpIndexService.getProvincial();
	}
	
	/**
	 * 首页初始化接口
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/indexdata")
	@ResponseBody
	public OperationResult getIndexData(HttpServletRequest request,HttpServletResponse response){
		return erpIndexService.getIndexData(request,response);
	}
	
	/**
	 * 根据ip获取地理位置接口（未完成）
	 * @param request
	 * @return
	 */
	@RequestMapping("/position")
	@ResponseBody
	public OperationResult getPosition(HttpServletRequest request){
		return erpIndexService.getPosition(request);
	}
	/**
	 * 密码重置(忘记密码)
	 * @param appUser
	 * @return
	 */
	@PostMapping("/resetPwd")
	@ResponseBody
	public OperationResult resetPwd(@RequestBody AppUser appUser,HttpServletRequest request){
		return erpIndexService.resetPwd(appUser,request);
	}
	/**
	 * 发送验证码
	 * @param email
	 * @param request
	 * @return
	 */
	@RequestMapping("/sendMailCode")
	@ResponseBody
	public OperationResult sendMailCode(String email,HttpServletRequest request){
		return erpIndexService.sendMailCode(email,request);
	}
	
	/**
	 * 获取省市区三级接口
	 * @return
	 */
	@RequestMapping("/region")
	@ResponseBody
	public OperationResult getAllRegions(){
		return erpIndexService.getAllRegions();
	}
	
	/**
	 * 获取省市区三级接口
	 * @return
	 */
	@RequestMapping("/region/{id}")
	@ResponseBody
	public OperationResult getRegionById(@PathVariable Long id){
		return erpIndexService.getRegionById(id);
	}
	
	/**
	 * 搜索框查询
	 * @param serverId
	 * @return
	 */
	@GetMapping("/getExpert")
	@ResponseBody
	public OperationResult getExpert(Long serverId,String type,HttpServletRequest request){
		return erpIndexService.getExpert(serverId,type,request);
	}
	
	/**
	 * 激活
	 * @param activateCode
	 * @param id
	 * @return
	 */
	@GetMapping("/activate")
	@ResponseBody
	public OperationResult activate(String activateCode,Long id){
		return erpIndexService.activate(activateCode,id);
	}
	
	/**
	 * 获取服务类型（申请专家服务页面）
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/getServerType")
	public OperationResult getServerType(){
		return erpIndexService.getServerType();
	}
	
	@ResponseBody
	@RequestMapping("/upload")
	public OperationResult upload(MultipartFile file){
		return erpIndexService.upload(file);
	}
	@ResponseBody
	@RequestMapping("/downlodInfo")
	public OperationResult downlodInfo(){
		return erpIndexService.downlodInfo();
	}
}
